package com.biostime.springdraw.modules.sd.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.springdraw.common.service.CrudService;
import com.biostime.springdraw.modules.sd.dao.WinnerDao;
import com.biostime.springdraw.modules.sd.dto.DistributedAwardDto;
import com.biostime.springdraw.modules.sd.dto.WinnerDto;
import com.biostime.springdraw.modules.sd.entity.Award;
import com.biostime.springdraw.modules.sd.entity.Section;
import com.biostime.springdraw.modules.sd.entity.Winner;
import com.biostime.springdraw.modules.sys.entity.User;

/**
 * 中奖表Service
 * @author king
 * @version 2016-01-18
 */
@Service
@Transactional
public class WinnerService extends CrudService<WinnerDao, Winner> {
	public ArrayList<LinkedHashMap<String,Object>> exportWinner(){
		return  dao.exportWinner();
	}

	public List<WinnerDto> getAllWinner(String openid){
		return dao.getAllWinner(openid);
	}

	public int getWinnerCount(Award award) {
		return dao.getWinnerCount(award);
	}

	public int findListBySection(Section section) {
		return dao.findListBySection(section);
	}

	public List<Winner> drawList(Winner winnerExm) {
		return dao.drawList(winnerExm);
	}
	
	public Winner selectByWinnerid(String winnerid){
		return dao.selectByWinnerid(winnerid);
	}
	
	@Transactional
	public int update(Winner winner){
		return dao.update(winner);
	}
	
	@Transactional
	public String  selectAndUpdate(Winner winner,String winnerid,HttpServletRequest request){
		Winner awardWinner = dao.selectByWinnerid(winnerid);
		String openid = request.getParameter("openid");
		if(awardWinner != null){
			awardWinner.setRecMobile(winner.getRecMobile()); 
			awardWinner.setRecAddr(winner.getRecAddr()); 
			awardWinner.setReceiver(winner.getReceiver()); 
			awardWinner.setUpdateBy(new User("0"));
			awardWinner.setUpdateDate(new Date()); 
			awardWinner.setPrizedOn(new Date()); 
			dao.update(awardWinner);
		}		
		return  openid;
	}
	
	public List<DistributedAwardDto> getSectionAwards(String code,int drawType){
		return dao.getSectionAwards(code,drawType);
	}
	
	public List<WinnerDto> getMyAwards(String openid){
		return dao.getMyAwards(openid);
	}
	
	public Winner getByCodeAndOpenid(String shareCode, String openid){
		return dao.getByCodeAndOpenid(shareCode, openid);
	}
	
	public int updateWinnerMemberId(Winner winner){
		return dao.updateWinnerMemberId(winner);
	}
	
	public void recoveryIntimeAward(){
		dao.recoveryIntimeAward();
	}
	
	public DistributedAwardDto getSectionDrawAwards(String code,String awardId, int drawType){
		return dao.getSectionDrawAwards(code, awardId , drawType);
	}
	
	public Winner getByOpenid(String shareCode, String openid){
		return dao.getByOpenid(shareCode, openid);
	}
}
